public class demo29 {
    public static void main(String[] args) throws InterruptedException {
        Object locker=new Object();
        Thread t1=new Thread(()->{
            for(int i=0;i<10;i++){
                synchronized(locker){
                    try {
                        locker.wait();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
                System.out.print("A");
                synchronized(locker){
                    locker.notify();
                }
            }
        });
        Thread t2=new Thread(()->{
            for(int i=0;i<10;i++){
                synchronized(locker){
                    try {
                        locker.wait();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
                System.out.print("B");
                synchronized(locker){
                    locker.notify();
                }
            }
        });
        Thread t3=new Thread(()->{
            for(int i=0;i<10;i++){
                synchronized(locker){
                    try {
                        locker.wait();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
                System.out.println("C");
                synchronized(locker){
                    locker.notify();
                }
            }

        });
        t1.start();
        t2.start();
        t3.start();
        // 要先唤醒A
        Thread.sleep(1000);
        synchronized (locker){
            locker.notify();
        }
    }
}
